/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package init;

import com.jme3.math.Vector3f;
import pieces.Piece;

/**
 *
 * @author david
 */
public class Initializer {
    
    public static void initializeChessboard() {
        
    }
    
    /**
     * updating soon.
     * @param whitePieces
     * @param blackPieces
     * @param positions 
     */
    public static void initializePiecesPositions(Piece[] whitePieces, Piece[] blackPieces, Vector3f[][] positions) {
        initializeWhitePieces(whitePieces, positions);
        initializeBlackPieces(blackPieces, positions);        
    }
    
     /**
     * updating soon.
     * @param whitePieces
     * @param positions 
     */
    private static void initializeWhitePieces(Piece[] whitePieces, Vector3f[][] positions) {        
        //king
        whitePieces[0].spatial.setLocalTranslation(positions[0][4]);
        
        //queen
        whitePieces[1].spatial.setLocalTranslation(positions[0][3]);
        
        //bishops
        whitePieces[2].spatial.setLocalTranslation(positions[0][2]);
        whitePieces[3].spatial.setLocalTranslation(positions[0][5]);
        
        //knights
        whitePieces[4].spatial.setLocalTranslation(positions[0][1]);
        whitePieces[5].spatial.setLocalTranslation(positions[0][6]);
        
        //rooks
        whitePieces[6].spatial.setLocalTranslation(positions[0][0]);
        whitePieces[7].spatial.setLocalTranslation(positions[0][7]);
        
        //pawns
        for (int i = 8; i < whitePieces.length; i++) {            
            whitePieces[i].spatial.setLocalTranslation(positions[1][i - 8]);
        }
    }
    
    /**
     * updating soon.
     * @param blackPieces
     * @param positions 
     */
    private static void initializeBlackPieces(Piece[] blackPieces, Vector3f[][] positions) {
        //king
        blackPieces[0].spatial.setLocalTranslation(positions[7][4]);
        
        //queen
        blackPieces[1].spatial.setLocalTranslation(positions[7][3]);
        
        //bishops
        blackPieces[2].spatial.setLocalTranslation(positions[7][2]);
        blackPieces[3].spatial.setLocalTranslation(positions[7][5]);
        
        //knights
        blackPieces[4].spatial.setLocalTranslation(positions[7][1]);
        blackPieces[5].spatial.setLocalTranslation(positions[7][6]);
        
        //rooks
        blackPieces[6].spatial.setLocalTranslation(positions[7][0]);
        blackPieces[7].spatial.setLocalTranslation(positions[7][7]);
        
        //pawns
        for (int i = 8; i < blackPieces.length; i++) {
            blackPieces[i].spatial.setLocalTranslation(positions[6][i - 8]);
        }
    }
    
   
    
    /**
     * Store into a vector all middle postions from chessboard.
     * @return Vector3f[][]
     */
    public static Vector3f[][] initializeMatrixPositions() {
        Vector3f[][] positions = new Vector3f[8][8];
        
        for (int i = 0; i < positions.length ; i++) {
            for (int j = 0; j < positions.length ; j++) {
                positions[i][j]= new Vector3f((float)(2 * j), 0.2f, (float)(-2 * i));
            }
        }        
        return positions;
    }
    
}
